using UnityEngine;

public class GameEndPermissions
{
	protected static bool CanRateAppBeShow()
	{
		if (!UserPreferences.instance.playerData.gameRated)
		{
			Globals instance = Globals.instance;
			int completedGamesNumber = UserPreferences.instance.playerData.completedGamesNumber;
			int num = completedGamesNumber - instance.rateAppPanelFirstAppearAfterLevel;
			if (num >= 0 && num % instance.rateAppPanelShowFrequency == 0)
			{
				return true;
			}
		}
		return false;
	}

	//protected static bool CanAdBeShow(bool isWin)
	//{
	//	if (!UserPreferences.instance.playerData.adsDisabled_IAP)
	//	{
	//		Globals instance = Globals.instance;
	//		int num = instance.showAdsFirstAppearAfterLevel;
	//		if (isWin)
	//		{
	//			num++;
	//		}
	//		if (UserPreferences.instance.playerData.progress <= num)
	//		{
	//			return false;
	//		}
	//		int completedGamesNumber = UserPreferences.instance.playerData.completedGamesNumber;
	//		int num2 = completedGamesNumber;
	//		if (num2 >= 0 && num2 % instance.showAdsFrequency == 0)
	//		{
	//			return true;
	//		}
	//	}
	//	return false;
	//}

	public static void ShowSpecialPanel(bool isWin)
	{
		if (CanRateAppBeShow())
		{
			DebugUtil.Log("Showing RateApp");
			ShowRateAppPanel();
		}
		//else if (CanAdBeShow(isWin))
		//{
		//	DebugUtil.Log("Showing Ad");
		//	ShowAd();
		//}
	}

	protected static void ShowRateAppPanel()
	{
		GameObject original = Resources.Load<GameObject>("Prefabs/UI_RateAppPanel");
		Object.Instantiate(original);
	}

	//public static void ShowAd()
	//{
	//	if (!UserPreferences.instance.playerData.adsDisabled_IAP)
	//	{
	//	//	AdsController adsController = Object.FindObjectOfType<AdsController>();
	//		//if (adsController != null)
	//		//{
	//		//	adsController.ShowInterstitialAd();
	//		//}
	//	}
	//}

	public static void IncreaseCompletedGamesNumber()
	{
		UserPreferences.instance.playerData.completedGamesNumber++;
		UserPreferences.instance.Save();
	}
}
